<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        canvas {
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <canvas width="600" height="400"></canvas>
</body>

</html>
<script>
    //获取DOM
    let canvas = document.querySelector('canvas');
    //获取上下文
    let ctx = canvas.getContext('2d');
    //绘制圆形
    ctx.beginPath();
    //绘制圆形的方法： 
    //  arc(x, y, radius, startAngle, endAngle, anticlockwise);  
    //  x、y,r,起始弧度、结束的弧度,是否逆时针绘制
    ctx.arc(100, 100, 50, 0, 2 * Math.PI, true);
    //设置填充颜色
    ctx.fillStyle = 'red';
    ctx.fill();
    //绘制圆形
    ctx.stroke();

    //绘制一个弧形
    // 弧度 = ( Math.PI / 180 ) * 角度
    ctx.beginPath();
    ctx.arc(200, 200, 50, 0, 1, false);
    ctx.stroke();

    for (i = 0; i < 12; i++) {
        ctx.beginPath();
        let x = 25 + i * 50;
        let y = 300;
        let endAngle = Math.PI + (Math.PI * i) / 12; // 从半圆到全圆

        ctx.arc(x, y, 20, 0, endAngle);
        ctx.fillStyle = 'skyblue';
        ctx.fill();
    }
</script>